home *** CD-ROM | disk | FTP | other *** search
- Path: osiris.ivy-ops.orbis.net!NewsWatcher!user
- From: kempkec@multiad.com (Christopher Kempke)
- Newsgroups: comp.lang.c++
- Subject: How to shrink your Windows program by %80!
- Date: 5 Mar 1996 20:50:32 GMT
- Organization: Multi-Ad Services, Inc.
- Message-ID: <kempkec-0503961448550001@205.164.77.10>
- NNTP-Posting-Host: 205.164.77.10
-
- Richard Champalbert writes:
- > How is that possable? Convert it to Pascal.
- >
- > Does anybody use Turbo Pascal (TP) for Windows? Having used only
- > BorlandC++ (BC) for Windows for the past few years, I was amazed to see
- > how much faster TP compiled and how much smaller the resulting code was.
- > If you have these two products try out a simple experiment: Write the
- > "hello world. program for Windows" with each compiler, then look and see.
- >
- > When I compiled with TP I thought that the compilation had stopped on an
- > error, but no, it was just _very_ fast. In my particular case I wrote a
- > very simple program to write a few lines of text in a window; a simple
- > task that I wanted to spend as little time writing as possible, so I used
- > OWL for BC, and the equivilent for TP.
- >
- > The size comparison: BC - 90k, TP - 14k!
- > The two programs do _exactly_ the same thing.
-
- No, they probably don't, as is clear from the fact that they're not the
- same size. Their _output_ is the same, which isn't the same thing at
- all. What you're seeing here is the difference in overhead between a
- pascal program and a C++ program. C++ is a more powerful language than
- Pascal, so it has more "setup." The difference in language complexity is
- also probably why Pascal compiles faster. From a compiler writer's
- standpoint, Pascal isn't just a simpler language than C++, it's a _MUCH
- SIMPLER_ language.
-
- What's especially deceptive about these numbers is that they are on such a
- small program. The 90K vs. 14K difference is vast, but 590K vs 514K
- wouldn't be,
- and I suspect (without proof, I'm primarily a Mac programmer) that the
- size difference doesn't magnify with the size of your program. Further,
- the Pascal program would almost certainly be larger, since one of the
- advantages of good C++ programs is code re-use.
-
- [snip]
- > Why does one compiler seem to be so much more efficient than the other?
- > There is always the argument that "you get all the C++ goodies", but using
- > TP you can do just about everything that you can do in BC, with seamingly
- > increadable savings on final exe size.
-
- Forgetting about Turing machines and universal models of computation and
- the like, let me state unequivocally that the above statement is false.
- C++ has built into it object-oriented and abstract data type abilities
- that Pascal can only dream of (even object-oriented Pascals). While it
- is true that you could duplicate _all_ of this in Pascal (by writing a C++
- compiler in Pascal, for example, which is perfectly possible and has
- probably even been done), you'd find that building such structures would
- increase the program size well beyond what you'd get by having started
- with a language that supported them.
-
- Bottom line - by using a more powerful language you can shrink the size of
- your code, but the cost is that the language itself becomes more
- expensive. Pascal and C++ are actually pretty close to each other on this
- spectrum, compare Pascal to a 4th-Generation database language for
- example. The 4GL is almost certainly easier to use, but enormously
- expensive in terms of resources to run.
-
- Note that all of this is a generalization -- a bad pascal compiler might
- well produce larger executables than an excellent C++ compiler even on
- small programs. But when the compilers are produced by the same company,
- probably even the same people, you have to believe language complexity is
- your culprit.
-